// 获取元素节点
let hotWord = document.querySelector('.hot-word');
let list = document.querySelector('.list');
// 切换输入框关键字
(function () {
  let hotWords = ['华为手机', '小米8', '苹果手机', '电脑', '图书', '户外', '冰箱', '教育'];
  let index = 0;
  setInterval(function () {
    index++;
    if (index >= hotWords.length - 1) {
      index = 0;
    }
    hotWord.placeholder = hotWords[index];
  }, 3000);
})();

// 模糊查询
let listArr = ['三星手机', '华为手机', '小米手机', '苹果手机', '苹果13', '苹果12', '魅族手机', '手表'];
hotWord.oninput = function () {
  list.innerHTML = '';
  let value = hotWord.value;
  for (let i = 0; i < listArr.length; i++) {
    if (listArr[i].indexOf(value) !== -1) {
      list.innerHTML = list.innerHTML + `<p>${listArr[i]}<p>`
      list.style.display = 'block';
    }

  }

}
// 失去焦点
hotWord.onblur = function () {
  list.style.display = 'none';
}